package com.doudou.collection.infrastructure.common.web;

import lombok.Data;

/**
 * @ClassName ResultVO<br>
 * @Description 统一响应结果封装类<br>
 * @Author 李浩文<br>
 * @Date 2023/6/2 17:24<br>
 * @Version 1.0<br>
 */
@Data
public class ResultVO {
    /**
     * 响应状态码
     */
    private int code;

    /**
     *服务端要返回给客户端的消息
     */
    private String message;

    /**
     *服务端要返回给客户端的具体数据
     */
    private Object data;

    public ResultVO() {
    }

    public ResultVO(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResultVO(int code, String message, Object data) {
        this(code, message);
        this.data = data;
    }

    public ResultVO(StatusCode statusCode, Object data) {
        this(statusCode.getCode(), statusCode.getMessage());
        this.data = data;
    }

    public ResultVO(StatusCode statusCode) {
        this(statusCode.getCode(), statusCode.getMessage());
    }

    public static ResultVO ok(Object data) {
        return new ResultVO(StatusCode.SUCCESS, data);
    }

    public static ResultVO ok() {
        return ok(null);
    }

    public static ResultVO error(StatusCode statusCode) {
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(statusCode.getCode());
        resultVO.setMessage(statusCode.getMessage());
        return resultVO;
    }

    public static ResultVO error(StatusCode statusCode, String message) {
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(statusCode.getCode());
        resultVO.setMessage(message);
        return resultVO;
    }
}
